package net.apexes.codegen.core;

import com.querydsl.codegen.EntityType;
import com.querydsl.codegen.Property;
import com.querydsl.codegen.Supertype;
import com.querydsl.codegen.utils.model.Type;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

/**
 * @author hedyn
 */
public class OrderableEntityType extends EntityType {

    public OrderableEntityType(Type type) {
        super(type);
    }

    public OrderableEntityType(Type type, Function<EntityType, String> variableNameFunction) {
        super(type, variableNameFunction);
    }

    public OrderableEntityType(Type type, Set<Supertype> superTypes) {
        super(type, superTypes);
    }

    @Override
    public Set<Property> getProperties() {
        Set<Property> properties = super.getProperties();
        List<Property> list = new ArrayList<>(properties);
        list.sort(new ColumnIndexComparator());
        return new LinkedHashSet<>(list);
    }

}
